//加载数据库驱动
const mysql = require('mysql');

//创建数据库连接
const connection = mysql.createConnection({
    host:'localhost',  //数据库所在的服务器的域名或者id地址
    user:'root',   //登录数据库的账号
    password:'5i_q4fF]iTY[9n48',   //登录数据库的密码
    database:'projects',   //数据库名称
});

connection.connect();  //执行连接操作

//操作数据库
connection.query('select count(*) as total from book', function (error, results, fields) {
    if (error) throw error;
    //console.log('The solution is: ', results[0].solution);  //The solution is:  2
    console.log("表中有", results[0].total + '条数据')   //表中有 7条数据
});

//关闭数据库
connection.end();